<?php
namespace control;
/*
*车辆档案类
*/

use JetBrains\PhpStorm\NoReturn;

class logisticsCarClass extends adIndexClass
{
    private const page = 'logisticsCar';
    private const table = 'logistics_car';
    private const title = '物流车辆档案';
    public array $stateOption = ['正常', '维修', '报废'];
    public array $illegalType = ['事故','违章'];

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            case 'feeSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'costDate' => [
                        'name'  => "报销日期",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'costType'  => [
                        'name'  => "报销类型",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'type'         => [
                        'name'  => '费用类型',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'applyDate'          => [
                        'name'  => '发生日期',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'money'    => [
                        'name'  => '费用金额（'.static::$unit.'）',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'text'    => [
                        'name'  => '费用说明',
                        'width' => 200,
                    ],
                    'stid'    => [
                        'name'  => '报销人',
                        'width' => 150,
                    ],
                    'deptName'    => [
                        'name'  => '报销人部门',
                        'width' => 150,
                    ],
                    'state'    => [
                        'name'  => '审批状态',
                        'width' => 150,
                    ],
                    'isPay'    => [
                        'name'  => '拨付状态',
                        'width' => 100,
                        'sort' => 1,
                    ]
                ];
                break;
            case 'gasSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'recordDate' => [
                        'name'  => "加油日期",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'gasStation'  => [
                        'name'  => "加油站",
                        'width' => 120,
                    ],
                    'gasNo'         => [
                        'name'  => '油号',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'volume'          => [
                        'name'  => '加油量（L）',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'price'    => [
                        'name'  => '单价（'.static::$unit.'/L）',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'money'    => [
                        'name'  => '金额（'.static::$unit.'）',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'payType'    => [
                        'name'  => '付款方式',
                        'width' => 120,
                    ],
                    'gasCard'    => [
                        'name'  => '油卡卡号',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'text'    => [
                        'name'  => '备注',
                        'width' => 150,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 150,
                    ]
                ];
                break;
            case 'tollSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'recordDate' => [
                        'name'  => "费用日期",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'gasStation'  => [
                        'name'  => "起始站",
                        'width' => 120,
                    ],
                    'gasNo'         => [
                        'name'  => '终点站',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'volume'          => [
                        'name'  => '公里数（KM）',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'price'    => [
                        'name'  => '单价（'.static::$unit.'/KM）',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'money'    => [
                        'name'  => '金额（'.static::$unit.'）',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'payType'    => [
                        'name'  => '付款方式',
                        'width' => 120,
                    ],
                    'gasCard'    => [
                        'name'  => '付款卡号',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'text'    => [
                        'name'  => '备注',
                        'width' => 150,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 150,
                    ]
                ];
                break;
            case 'illegalSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'recordDate' => [
                        'name'  => "登记日期",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'type'  => [
                        'name'  => "类型",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'description'         => [
                        'name'  => '描述',
                        'width' => 200,
                    ],
                    'happenTime'          => [
                        'name'  => '发生时间',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'address'    => [
                        'name'  => '发生地点',
                        'width' => 200,
                    ],
                    'responsibility'    => [
                        'name'  => '责任',
                        'width' => 200,
                    ],
                    'score'    => [
                        'name'  => '扣分',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'fine'    => [
                        'name'  => '罚款('.static::$unit.')',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'reparation'    => [
                        'name'  => '赔偿('.static::$unit.')',
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 100,
                    ]
                ];
                break;
            case 'repairSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 150,
                    ],
                    'recordDate' => [
                        'name'  => "维修日期",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'reason'  => [
                        'name'  => "维修原因",
                        'width' => 250,
                    ],
                    'text'         => [
                        'name'  => '维修内容',
                        'width' => 250,
                    ],
                    'factory'          => [
                        'name'  => '修配厂',
                        'width' => 250,
                        'sort' => 1,
                    ],
                    'money'    => [
                        'name'  => '维修费用('.static::$unit.')',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 200,
                    ]
                ];
                break;
            case 'maintainanceSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'recordDate' => [
                        'name'  => "保养日期",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'text'  => [
                        'name'  => "保养内容",
                        'width' => 200,
                    ],
                    'factory'         => [
                        'name'  => '修配厂',
                        'width' => 150,
                    ],
                    'money'          => [
                        'name'  => '保养费用('.static::$unit.')',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'mileage'    => [
                        'name'  => '当前里程(km)',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'nextMileage'    => [
                        'name'  => '下次保养里程(km)',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'nextDate'    => [
                        'name'  => '下次保养日期',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'isWarn'    => [
                        'name'  => '到期预警',
                        'width' => 120,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 120,
                    ]
                ];
                break;
            case 'inspectionSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'checkDate' => [
                        'name'  => "检验日期",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'agency'  => [
                        'name'  => "检验机构",
                        'width' => 250,
                        'sort' => 1,
                    ],
                    'markNo'         => [
                        'name'  => '合格标志号',
                        'width' => 250,
                        'sort' => 1,
                    ],
                    'endDate'          => [
                        'name'  => '检验有效期至',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'text'    => [
                        'name'  => '备注',
                        'width' => 200,
                    ],
                    'isWarn'    => [
                        'name'  => '到期预警',
                        'width' => 200,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 150,
                    ]
                ];
                break;
            case 'insureSearch':
                $tr = [
                    'fileBtn'      => [
                        'name'  => "附件",
                        'width' => 100,
                    ],
                    'recordDate' => [
                        'name'  => "登记日期",
                        'width' => 120,
                        'sort' => 1,
                    ],
                    'insurer'  => [
                        'name'  => "保险人",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'startDate'         => [
                        'name'  => '保险期间',
                        'width' => 250,
                        'sort' => 1,
                    ],
                    'insureFee'          => [
                        'name'  => '保费(' . static::$unit . ')',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'insureMoney'    => [
                        'name'  => '保额',
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'text'    => [
                        'name'  => '备注',
                        'width' => 200,
                    ],
                    'isWarn'    => [
                        'name'  => '到期预警',
                        'width' => 200,
                    ],
                    'stid'    => [
                        'name'  => '经办人',
                        'width' => 200,
                    ]
                ];
                break;
            default:
                $tr = [
                    'orderNo'          => [
                        'name'  => '车辆编号',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'carNo' => [
                        'name'  => "车牌号",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'brand'  => [
                        'name'  => "车辆品牌",
                        'width' => 100,
                    ],
                    'model'  => [
                        'name'  => "规格型号",
                        'width' => 150,
                    ],
                    'carType'  => [
                        'name'  => "车辆类型",
                        'width' => 150,
                    ],
                    'managerId'         => [
                        'name'  => '负责人',
                        'width' => 100,
                    ],
                    'time'          => [
                        'name'  => '登记日期',
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'nextInsureDate'          => [
                        'name'  => '下次续保日期',
                        'width' => 150,
                    ],
                    'nextInspectionDate'          => [
                        'name'  => '下次年审日期',
                        'width' => 150,
                    ],
                    'state'          => [
                        'name'  => '状态',
                        'width' => 150,
                    ]
                ];
        }
        return $tr;
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "车辆编号" => text(array("name" => "orderNo")),
                    "车牌号"   => text(array("name" => "carNo")),
                    "车辆品牌"   => text(array("name" => "brand")),
                ],
                [
                    "规格型号"   => text(array("name" => "model")),
                    '车辆类型' => select(array("name" => "type", "option" => explode('，', para('carType')))),
                    "登记日期" => text(array("name" => "createTime", 'laydate' => ['type' => 'date', 'range' => '~'])),
                ],
                [
                    "状态"   => select(array("name" => "state", "option" => $this->stateOption)),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /*列表-查询条件*/
    public function home()
    {
        $html = $this->homeOptions(false);
        //控件
        $button = "";
        $url = root . "control/adIndex.html?cla=" . self::page;
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('".self::page."','edit')\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'del'})\">删除</span>\n";
        }
        if ($this->power(self::page, 'import')) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','importFrame',{cla:'".self::page."'})\">导入</span>";
        }
        if ($this->power(self::page, "export")) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','exportFrame',{cla:'".self::page."'})\">导出</span>";
        }
        //返回
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    /*客户列表-查询结果*/
    public function homeSearch()
    {
        //like查询数组
        $like = array(
            "orderNo" => $this->post('orderNo'),//车辆编号
            "carNo" => $this->post('carNo'),//车牌号
            "brand" => $this->post('brand'),//车辆品牌
            "model" => $this->post('model'),//规格
        );
        //全等查询数组
        $equal = array(
            "state" => $this->post('state'),//状态
            "carType" => $this->post('type'),//类型
            'coid' => self::$coid
        );
        $and = "";
        if ($this->post('createTime')) {
            $and .= self::timeComparison($this->post('createTime'));
        }
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $where = search(array("like" => $like, "=" => $equal)) . $and;
        $page = $this->page(array("table" => self::table, "where" => $where, "order" => $orderBy['orderBy']));
        $_SESSION[self::page]['sql'] = $page['fullSql'];
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("listForm", "listId")
        );
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box" => array("name" => "listId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','edit',{id:'" . $array['id'] . "'})"),
                "detail" => array("title" => self::title . "详情", "click" => "newIframe('" . self::title . "详情','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case 'carNo':
                        $row[] = $array['shortName'] . $array['carNo'];
                        break;
                    case 'managerId':
                        $row[] = self::findStaff($array['managerId']);
                        break;
                    case 'nextInsureDate':
                        $nextInsureDate = query("logistics_car_insure"," carId = '".$array['id']."' and coid = '" . self::$coid . "' order by endDate desc  ");
                        $row[] = $nextInsureDate['endDate'];
                        break;
                    case 'nextInspectionDate':
                        $nextInspectionDate = query("logistics_car_inspection"," carId = '".$array['id']."' and coid = '" . self::$coid . "' order by endDate desc  ");
                        $row[] = $nextInspectionDate['endDate'];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . $li . "</form>" . $page['button'] . clear;
        return json_encode($json, 320);
    }

    /**
     * 下载模板
     */
    public function downloadModel()
    {
        $templateId = $this->get('templateId');
        if (!$this->power(self::page, 'edit')) {
            $_SESSION['warn'] = '你还没有编辑的权限';
        }  else {
            $exampleData[] = ['YM202101010001','渝A00001', '长安', 'CS55', 'SUV', '6', '500', '汽油', '1.5T', '1121212121', '100000', '2021-01-01', '王海', 'YM202111220002', '30', '10', '正常', '样例数据，导入数据时请删除此行'];

            $excel    = $this->excelHead();
            $fileName = self::title.'导入模板-'.importTemplateClass::getName($templateId).'.xlsx';
            $filePath = $excel->fileName($fileName, 'sheet1');
            $format = new \Vtiful\Kernel\Format($filePath->getHandle());
            $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
            $index         = 0;
            foreach ($templateField as $k => $array) {
                if ($array['display']){
                    $backgroundStyle=null;
                    if (importTemplateClass::getIsMustValue($this->importFieldInit(), $array['columnName'])){
                        //必填项判断
                        $backgroundStyle  = $format->background(
                            0xFFC04B
                        )->toResource();
                    }
                    $filePath->insertText(0, $index, $array['aliasName'],'',$backgroundStyle);
                    foreach ($exampleData as $y=>$example){
                        $exampleVal = match ($array['columnName']){
                            '车牌号'=>$example[0],
                            '车辆品牌'=>$example[1],
                            '规格型号'=>$example[2],
                            '车辆类型'=>$example[3],
                            '核定载人数'=>$example[4],
                            '核定载重'=>$example[5],
                            '燃油类型'=>$example[6],
                            '排量'=>$example[7],
                            '车架号'=>$example[8],
                            '资产原值'=>$example[9],
                            '开始使用日期'=>$example[10],
                            '管理员'=>$example[11],
                            '管理员编号'=>$example[12],
                            '使用期限'=>$example[13],
                            '折价期限'=>$example[14],
                            '状态'=>$example[15],
                            '备注'=>$example[16],
                            default=>'',
                        };
                        $filePath->insertText($y+1, $index, $exampleVal);
                    }
                    $index++;
                }
            }
            $text = $this->control['name'] . "下载了车辆档案导入模板";
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOutPut($filePath,$fileName);
            exit(0);
        }
        header("Location:" . getenv("HTTP_REFERER"));
    }

    /*数据导入分析*/
    public function importData()
    {
        $templateId = $this->post('templateId');
        if (!$this->power(self::page, 'edit')) {
            $json['warn'] = '你还没有编辑的权限';
        }  else {
             $fomatArray = [];//导入数据格式同一为TYPE_STRING
            foreach ($this->importFieldInit() as $value){
                $fomatArray[] = \Vtiful\Kernel\Excel::TYPE_STRING;
            }
            $data = $this->importHead(format: $fomatArray);
            $x = 0;
            $text = '';
            $headArray = [];
            $row_list=0;
            foreach ($data as $i => $row) {
                $row_list++;
                if ($i==0){
                    $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
                    $headArray = importTemplateClass::combinHead($templateField,$row);
                }
                if ($i > 0) {
                    //只接收模板中选中的字段的值
                    $cell = [];
                    foreach ($headArray as $index=>$headName){
                        $cell[$headName] = $rowData[$index]??'';
                    }
                    //初始化未被模板需要的字段的值
                    foreach ($this->importFieldInit() as $value){
                        $cell[$value['columnName']] = $cell[$value['columnName']]??'';
                    }
                    $staff = query("staff", "orderNo = '$cell[管理员编号]'");
                    $shortName = mb_substr($cell['车牌号'], 0, 1, 'utf8');
                    $carNo = mb_substr($cell['车牌号'], 1);
                    $field = array(
                        "id" => self::getId(),
                        'coid' => self::$coid,
                        'stid' => $this->control['stid'],
                        'shortName' => $shortName,
                        'carNo' => $carNo,
                        'brand' => $cell['车辆品牌'],
                        'model' => $cell['规格型号'],
                        'carType' => $cell['车辆类型'],
                        'maxPeople' => $cell['核定载人数'],
                        'maxWeight' => $cell['核定载重'],
                        'volume' => $cell['排量'],
                        'gasType' => $cell['燃油类型'],
                        'frameNo' => $cell['车架号'],
                        'money' => $cell['资产原值'],
                        'buyDate' => self::importDateFormat($cell['开始使用日期']),
                        'managerId' => $staff['stid'],
                        'maxMonth' => $cell['使用期限'],
                        'discountMonth' => $cell['折价期限'],
                        'text' => $cell['备注'],
                        'state' => $cell['状态'],
                        'updateTime' => $this->time,
                        "time" => date("Y-m-d H:i:s"),
                    );
                    $userNo = codeTemplateClass::generateCode(self::page,[
                        'prefix' => 'CAR',
                        'table' => self::table,
                        'field' => 'orderNo',
                        'where' => '',
                    ],$field);
                    $field['orderNo'] = $userNo;

                    $annotation = [
                        'shortName' => '车牌号',
                        'carNo' => '车牌号',
                        'brand' => '品牌',
                        'carType' => '车辆类型',
                        'maxPeople' => '核定载人数',
                        'maxWeight' => '核定载重',
                        'gasType' => '燃油类型',
                        'volume' => '排量',
                        'buyDate' => '开始使用日期',
                        'managerId' => '管理员',
                    ];
                    $rules = [
                        'shortName' => 'required',
                        'carNo' => 'required',
                        'brand' => 'required',
                        'carType' => 'required',
                        'maxPeople' => 'required|numeric',
                        'maxWeight' => 'required|numeric',
                        'gasType' => 'required',
                        'volume' => 'required',
                        'buyDate' => 'required|date',
                        'managerId' => 'required',
                    ];
                    // 校验是否符合规则
                    $vt = new \verify();
                    $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
                    if (empty($field['managerId']) || !$staff['stid']) {
                        $text .= "第【{$row_list}】行：未通过员工编号找到此管理员<br>";
                    } elseif ($result === false) {
                        $text .= "第【{$row_list}】行：" . $vt->getErrs()[0] . "<br>";  // 多个规则提示最前面一条
                    } elseif (static::total(array('table' => "logistics_car", 'where' => " and coid = '".self::$coid."' and carNo ='$field[carNo]' and shortName = '$field[shortName]' and id !='$field[id]'")) > 0) {
                        $text .= "第【{$row_list}】行：已存在此车牌号<br>";
                    }else {
                        $warn = static::insert(["table" => self::table, "field" => $field]);
                        if (in_array($warn, ["新增成功", "更新成功"])) {
                            $x++;
                            $text .= "第【{$row_list}】行：导入成功<br>";
                        } else {
                            $text .= "第【{$row_list}】行：导入失败：编辑失败<br>";
                        }
                    }
                }
            }
            $total = count($data)-1;
            $json['data'] = [
                'text'=>$text,
                'title'=>"您导入了{$total}条数据，成功{$x}条，失败".($total-$x)."条",
            ];
            $text = $this->control['name'] . '导入了文件：' . $_FILES['file']['name'] . '：' . $text;
            $this->logText(["type" => self::page, "text" => $text]);
            $json['warn'] = 2;
        }
        return json_encode($json,320);
    }

    /**
     * 导出
     */
    public function exportData()
    {
        $templateId = $this->get('templateId');
        $checkedId = $this->get('checkedId')?explode(',',$this->get('checkedId')):[];
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = '你还没有导出的权限';
        }   else {
            $data = [];
            /***********标题**********/
            $title =[];
            $tempFieldAll = importTemplateClass::templateField(self::page, 'exportFieldInit', id:$templateId);
            foreach ($tempFieldAll as $array) {
                if ($array['display']){
                    $title[] = $array['aliasName'];
                }
            }
            //判断是否选中导出
            if (!self::is_null_array($checkedId)){
                $result = find(array(
                    "table" => self::table,
                    "where" => "id in ('".implode("','", $checkedId)."') order by time desc",
                ))['array'];
            }else{
                $sql   = $_SESSION[self::page]['sql'];
                $result   = sqlFind($sql);
            }
            //导出数据生成
            foreach ($result as $array){
                $column = [];
                $driver = query('logistics_driver',"id = '$array[deiverId]'");
                foreach ($tempFieldAll as $templateField){
                    if ($templateField['display']){
                        $column[] = match ($templateField['columnName']){
                            '车辆编号'=>$array['orderNo'],
                            '车牌号'=>$array['shortName'] . $array['carNo'],
                            '车辆品牌'=>$array['brand'],
                            '规格型号'=>$array['model'],
                            '车辆类型'=>$array['carType'],
                            '核定载人数'=>$array['maxPeople'],
                            '核定载重'=>$array['maxWeight'],
                            '燃油类型'=>$array['gasType'],
                            '排量'=>$array['volume'],
                            '车架号'=>$array['frameNo'],
                            '资产原值'=>$array['money'],
                            '开始使用日期'=>$array['buyDate'],
                            '管理员'=>self::findStaff($array['managerId']),
                            '使用期限'=>$array['maxMonth'],
                            '折价期限'=>$array['discountMonth'],
                            '驾驶人'=>$driver['name'],
                            '状态'=>$array['state'],
                            '备注'=>$array['text'],
                            '创建人'=>self::findStaff($array['stid']),
                            '创建时间'=>$array['time'],
                            default=>'',
                        };
                    }
                }
                $data[] = $column;
            }
            $text = $this->control['name'] . "导出了车辆档案";
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $data, "车辆档案.xlsx");
            exit(0);
        }
        header("Location:" . getenv("HTTP_REFERER"));
    }

    /**
     * 编辑页
     * @return string
     */
    public function edit()
    {
        $id = $this->post('id');
        $info = query(self::table, " id = '" . $this->post('id') . "' ");
        //表单
        $html = $this->layerEdit([
            "table" => [
                [
                    must . "车牌号：" => select(["name" => "shortName", 'option' => explode('，', para('shortNameOption')), "value" => $info['shortName']]) . text(["name" => "carNo", 'class' => 'text', "value" => $info['carNo']]),
                    must . "车牌品牌：" => text(["name" => "brand", 'class' => 'text', "value" => $info['brand']]),
                ],
                [
                    "规格型号：" => text(["name" => "model", 'class' => 'text', "value" => $info['model']]),
                    must . "车辆类型：" => select(["name" => "type", 'title' => '类型', 'option' => explode('，', para('carType')), "value" => $info['carType']]),
                ],
                [
                    must . "核定载人数：" => text(["name" => "maxPeople", 'type' => 'number', 'class' => 'text', "value" => $info['maxPeople']]),
                    must . "核定载重：" => text(["name" => "maxWeight", 'type' => 'number', 'unit' => 'kg', 'class' => 'text', "value" => $info['maxWeight']]),
                ],
                [
                    must . "燃油类型：" => select(["name" => "gasType", 'option' => explode('，', para('gasType')), 'class' => 'text', "value" => $info['gasType']]),
                    must . "排量：" => text(["name" => "volume", 'class' => 'text', "value" => $info['volume']]),
                ],
                [
                    "车架号：" => text(["name" => "frameNo", 'class' => 'text', "value" => $info['frameNo']]),
                    must . "资产原值：" => text(["name" => "money", 'type' => 'number', 'unit' =>  static::$unit , 'class' => 'text', "value" => $info['money']]),
                ],
                [
                    must . "开始使用日期：" => text(["name" => "buyDate", 'laydate' => [], 'class' => 'text', "value" => $info['buyDate']]),
                    must . "管理员：" => selectMultiple(["name" => "managerId", 'title' => '管理员', 'table' => "staff", 'sqlId' => 'stid', 'sqlField' => 'name', "value" => $info['managerId']]),
                ],
                [
                    "使用期限：" => text(["name" => "maxMonth", 'unit' => '月', 'class' => 'text', "value" => $info['maxMonth']]),
                    "折价期限：" => text(["name" => "discountMonth", 'unit' => '月', 'class' => 'text', "value" => $info['discountMonth']]),
                ],
                [
                    '驾驶员' => selectMultiple(array('name' => 'driverId', 'table' => 'logistics_driver', 'sqlId' => 'id', 'sqlField' => 'name', 'value' => $info['driverId'], 'title' => '请选择', 'where' => " coid = '" . self::$coid . "' "))
                ],
                [
                    "备注：" => textarea(["name" => "text", 'class' => 'textarea', "value" => $info['text']]),
                ],
                [
                    "车辆图片(最大4张)：" => fileUploadClass::addImgComponent($id, '车辆图片', self::page, self::page . 'EditForm')
                ],
            ],
        ]);
        //返回
        return $this->layer(array("title" => L('job.button.editor').self::title, "height" => 600, "html" => $html));
    }

    public function editEdit()
    {
        $fileId = $this->post('imgId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'shortName' => $this->post('shortName'),
            'driverId' => $this->post('driverId'),
            'carNo' => $this->post('carNo'),
            'brand' => $this->post('brand'),
            'model' => $this->post('model'),
            'carType' => $this->post('type'),
            'maxPeople' => $this->post('maxPeople'),
            'maxWeight' => $this->post('maxWeight'),
            'volume' => $this->post('volume'),
            'gasType' => $this->post('gasType'),
            'frameNo' => $this->post('frameNo'),
            'money' => $this->post('money'),
            'buyDate' => $this->post('buyDate'),
            'managerId' => $this->post('managerId'),
            'maxMonth' => $this->post('maxMonth'),
            'discountMonth' => $this->post('discountMonth'),
            'text' => $this->post('text'),
            'updateTime' => $this->time
        ];
        $annotation = [
            'shortName' => '车牌号',
            'carNo' => '车牌号',
            'brand' => '品牌',
            'carType' => '车辆类型',
            'maxPeople' => '核定载人数',
            'maxWeight' => '核定载重',
            'gasType' => '燃油类型',
            'volume' => '排量',
            'buyDate' => '开始使用日期',
            'managerId' => '管理员',
        ];
        $rules = [
            'shortName' => 'required',
            'carNo' => 'required',
            'brand' => 'required',
            'carType' => 'required',
            'maxPeople' => 'required',
            'maxWeight' => 'required',
            'gasType' => 'required',
            'volume' => 'required',
            'buyDate' => 'required',
            'managerId' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } elseif (static::total(array('table' => "logistics_car", 'where' => " and coid = '".self::$coid."' and carNo ='$field[carNo]' and shortName = '$field[shortName]' and id !='$id'")) > 0) {
            $json['warn'] = '已存在此车牌号';
        } else {
            $where = " id = '$id' ";
            $info = query(self::table, $where);
            if (!$info['id']) {
                $userNo = codeTemplateClass::generateCode(self::page,[
                    'prefix' => 'CAR',
                    'table' => self::table,
                    'field' => 'orderNo',
                    'where' => '',
                ],$field);
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                    'orderNo' => $userNo,
                    'stid' => $this->control['stid'],
                    'state' => '正常',
                    'time' => $this->time
                ]);
                $json['warn'] = static::insert(["table" => self::table, "field" => $field]);
            } else {
                $json['warn'] = static::update([
                    "table" => self::table,
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //更新文件
                update(array('table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"));
                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&id=" . $id;
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*详情页*/
    public function detail(): string
    {
        $info = query(self::table, " id = '{$this->get('id')}'");
        if (empty($info['id'])) {
            $html = '未找到此' . self::title;
        } else {
            //菜单
            $data = array(
                "id" => $info['id'],
                "title" => self::title . '详情',
                'menu' => [
                    "detail" => "基本信息",
                    'insure' => '保险记录',
                    'inspection' => '年审记录',
                    'maintainance' => '保养记录',
                    'repair' => '维修记录',
                    'illegal' => '事故违章',
                    'gas' => '加油记录',
                    'toll' => '过路费',
                    'fee' => '费用汇总',
                ]
            );

            $button = [];
            if ($this->power(self::page, "edit")) {
                //按钮
                $button[] = [
                    "name" => "编辑",
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "edit",
                    "post" => ["id" => $info['id']],
                    'style' => 'li-btn-blue-bg',
                ];
                switch ($info['state']) {
                    case '报废':
                        $firState = '正常';
                        $secState = '维修';
                        $titleOne = '正常';
                        $titleTwo = '维修';
                        break;
                    case '维修':
                        $firState = '正常';
                        $secState = '报废';
                        $titleOne = '正常';
                        $titleTwo = '报废';
                        break;
                    default:
                        $firState = '维修';
                        $secState = '报废';
                        $titleOne = '维修';
                        $titleTwo = '报废';
                        break;
                }
                //按钮
                $button[] = [
                    "name" => $titleOne,
                    "type" => "点击事件",
                    "cla" => $this->get('cla'),
                    "fun" => "layer('" . $this->get('cla') . "','stateSwitch',{type:'{$firState}',id:'{$info['id']}'})",
                ];
                //按钮
                $button[] = [
                    "name" => $titleTwo,
                    "type" => "点击事件",
                    "cla" => $this->get('cla'),
                    "fun" => "layer('{$this->get('cla')}','stateSwitch',{type:'{$secState}',id:'{$info['id']}'})",
                ];

            }
            if ($this->power(self::page,'del')){
                //按钮
                $button[] = [
                    "name" => "删除",
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "operate",
                    "post" => ["act" => 'del', "id" => $info['id']],
                ];
            }
            $driver = query('logistics_driver', "id = '$info[driverId]'");
            //生成表单
            $data['button'] = $this->tableShowButton($button);
            $data['html'] = $this->tableShow(array(
                '详细信息' => array(
                    array(
                        "车牌号" => $info['shortName'] . $info['carNo'],
                        "车辆品牌" => $info['brand'],
                        "规格型号" => $info['model'],
                        "车辆类型" => $info['carType'],
                    ),
                    array(
                        "核定载人数(人)" => $info['maxPeople'],
                        "核定载重(kg)" => $info['maxWeight'],
                        "燃油类型" => $info['gasType'],
                        "排量" => $info['volume'],
                    ),
                    array(
                        "车架号" => $info['frameNo'],
                        "资产原值(". static::$unit . ")" => $info['money'],
                        "开始使用日期" => $info['buyDate'],
                        "使用期限(月)" => $info['maxMonth'],
                    ),
                    array(
                        "折价期限(月)" => $info['discountMonth'],
                        "管理员" => self::findStaff($info['managerId']),
                        "驾驶员" => $driver['name'],
                    ),
                    array(

                        "备注" => pre($info['text']),
                    ),
                ),
                '系统信息' => array(
                    array(
                        "车辆编号" => $info['orderNo'],
                        "创建人" => self::findStaff($info['stid']),
                        "创建时间" => $info['time'],
                        "更新时间" => $info['updateTime'],
                    ),
                    array(
                        "状态" => $info['state'],
                    ),
                ),
                '车辆图片' => [
                    [
                        fileUploadClass::showImg($info['id'], '车辆图片')
                    ]
                ],

            ));
            //生成页面
            $html = $this->tab($data);
        }
        //返回
        return $html;
    }

    // 操作中转
    public function operate()
    {
        $act = $this->post('act') ?? '';
        $pwd = false; // 需要密码
        $form = $power = '';
        switch ($act) {
            case 'insureDel':
                $act = 'del';
                $msg = '删除车辆保险记录';
                $title = self::page . 'DeleteInsure';
                $function = 'deleteInsure';
                $form = self::page . 'OperateForm, insureForm';
                $power = '';
                break;
            case 'inspectionDel':
                $act = 'del';
                $msg = '删除车辆年检记录';
                $title = self::page . 'DeleteInspection';
                $function = 'deleteInspection';
                $form = self::page . 'OperateForm, inspectionForm';
                break;
            case 'maintainanceDel':
                $act = 'del';
                $msg = '删除车辆保养记录';
                $title = self::page . 'DeleteMaintainance';
                $function = 'deleteMaintainance';
                $form = self::page . 'OperateForm, maintainanceForm';
                break;
            case 'repairDel':
                $act = 'del';
                $msg = '删除车辆维修记录';
                $title = self::page . 'DeleteRepair';
                $function = 'deleteRepair';
                $form = self::page . 'OperateForm, repairForm';
                break;
            case 'illegalDel':
                $act = 'del';
                $msg = '删除车辆事故违章记录';
                $title = self::page . 'DeleteIllegal';
                $function = 'deleteIllegal';
                $form = self::page . 'OperateForm, illegalForm';
                break;
            case 'gasDel':
                $act = 'del';
                $msg = '删除车辆加油记录';
                $title = self::page . 'DeleteGas';
                $function = 'deleteGas';
                $form = self::page . 'OperateForm, gasForm';
                break;
            default:
                $act = 'del';
                $msg = '删除' . self::title;
                $title = self::page . 'Delete';
                $function = 'delete';
                $form = self::page . 'OperateForm, listForm';
                $power = '';
                break;
        }
        if (!$this->power(self::page, $act)) {
            $_SESSION['warn'] = '你还没有' . $msg . '的权限';
            $json = [
                'warn' => 2,
                'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
            ];
        } else {
            return $this->confirm([
                'title' => $title,
                'function' => $function,
                'form' => $form,
                'power' => $power,
                'pwd' => $pwd,
            ]);
        }

        resp:
        return json_encode($json, 320);
    }

    /**
     * 删除加油记录
     * @return bool|string
     */
    public function deleteGas(): bool|string
    {
        $array = $this->post('gasId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_gas', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_gas', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的车辆加油记录：登记日期:【{$mx['recordDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆加油记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个加油记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=gas&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }

    /**
     * 删除过路费记录
     * @return bool|string
     */
    public function deleteToll(): bool|string
    {
        $array = $this->post('gasId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_toll', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_toll', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的车辆过路费记录：登记日期:【{$mx['recordDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆过路费记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个过路费记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=toll&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }

    /**
     * 删除车辆事故违章记录
     * @return bool|string
     */
    public function deleteIllegal(): bool|string
    {
        $array = $this->post('illegalId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_illegal', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_illegal', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的车辆事故违章记录：登记日期:【{$mx['recordDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆事故违章记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个事故违章记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=illegal&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }
    /**
     * 删除车辆维修记录
     * @return bool|string
     */
    public function deleteRepair(): bool|string
    {
        $array = $this->post('repairId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_repair', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_repair', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的维修记录：维修日期:【{$mx['recordDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆维修记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个维修记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=repair&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }
    /**
     * 删除车辆保险记录
     * @return bool|string
     */
    public function deleteMaintainance(): bool|string
    {
        $array = $this->post('maintainanceId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_maintainance', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_maintainance', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的保养记录：保养日期:【{$mx['recordDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆保养记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个保养记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=maintainance&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }
    /**
     * 删除年检记录
     * @return bool|string
     */
    public function deleteInspection(): bool|string
    {
        $array = $this->post('inspectionId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_inspection', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_inspection', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的年检记录：检验日期:【{$mx['checkDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆年检记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个年检记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=inspection&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }
    /**
     * 删除保险
     * @return bool|string
     */
    public function deleteInsure(): bool|string
    {
        $array = $this->post('insureId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query('logistics_car_insure', " id = '$id' ");
                $info = query(self::table, " id = '$mx[carId]'");
                delete(array("table" => 'logistics_car_insure', "where" => " id = '$id' "));
                $all = find(array('table'=>'file','where'=>"targetId = '$id'"));
                foreach ($all['array'] as $val){
                    fileDelete($val['src']);
                    delete(array("table" =>'file', "where" => " id = '$val[id]' "));
                }
                //返回
                $warn = "删除成功";
                $x++;
                $text .= "车辆【" . $info['orderNo'] . "】的保险记录：期间:【{$mx['startDate']}~{$mx['endDate']}】,ID:{$mx['id']}" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了车辆保险记录，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个保险记录，详情见系统日志。";
            $json['warn'] = 2;
            $info['carId']= $info['carId']??'';
            $json['href'] = $info['carId']?root . 'control/adIndex.html?cla=' . $this->get('cla') . "&fun=detail&menu=insure&id=" . $info['carId']:'';
        }
        return json_encode($json, 320);
    }

    /**
     * 删除
     * @return bool|string
     */
    public function delete()
    {
        $array = $this->post('listId') ?? $this->post('id');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $info = query(self::table, " id = '$id' ");

                //最后删除基本参数
                delete(array("table" => self::table, "where" => " id = '$id' "));
                //返回
                $warn = "删除成功";
                $x++;

                $text .= self::title . "ID【" . $info['id'] . "】" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了" . self::title . "，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个" . self::title . "，详情见系统日志。";
            $json['warn'] = 2;
            $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=home";
        }
        return json_encode($json, 320);
    }

    /**
     * 启用/停用
     */
    public function stateSwitch()
    {
        $type = $this->post('type');
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                "提示：" => "是否更改此车辆状态为：" . $type,
            ),
        ), 'hidden' => hidden(array('name' => 'type', 'value' => $type))));
        //返回
        return $this->layer(array("title" => "状态切换", "height" => 165, "html" => $html));
    }

    /**
     * 启用/停用
     */
    public function stateSwitchEdit()
    {
        $id = $this->post('id');
        $type = $this->post('type');
        $info = query(self::table, " id = '$id'");
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有" . self::title . "的编辑权限";
        } elseif (empty($info['id'])) {
            $json['warn'] = "未找到此" . self::title;
        } elseif (!in_array($type, $this->stateOption)) {
            $json['warn'] = "类型错误";
        } else {
            $field = [
                'state' => $type,
            ];
            $json['warn'] = update(array('table' => self::table, 'field' => $field, 'where' => " id ='$id'"));
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . "的状态为【{$type}】， id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
            }
        }
        //返回
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function feeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "报销人部门" => text(array("name" => "deptName")),
                    "报销类型"   => select(["name" => "type", 'class' => 'text', 'option' => explode('，', para('reimburseType'))]),
                    '费用类型' => select(["name" => "costType", 'class' => 'text', 'option' => explode('，', para('costType'))]),
                ],
                [
                    '审批状态'  => select(array("name" => "state", "option" => ['草稿','审核中','已通过'])),
                    "拨付状态" => select(array("name" => "isPay", "option" => ['是','否'])),
                    '发生日期' => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])),
                ],
                [
                    '报销日期' => text(array("name" => "createTime", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 费用汇总
     */
    public function fee(): bool|string
    {
        $html = $this->feeOptions(false);
        //控件
        $button = "";
        if ($this->power(self::page, "export")) {
            $button .= "  <a href='" . root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=exportFeeData'><span class='spanButton'>导出</span></a>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 费用汇总
     * @return bool|string
     */
    public function feeSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and a.targetId = '$carId' and a.coid = '" . self::$coid . "' ";
        $and = '';
        $like = [
            "a.deptName" => $this->post('deptName'),
        ];
        $equal = [
            "a.state" => $this->post('state'),
            "a.type" => $this->post('type'),
            "b.type" => $this->post('costType'),
        ];
        if ($this->post('isPay') =='是'){
            $and.=" and isPay = 1";
        }elseif($this->post('isPay') =='否'){
            $and.=" and isPay = 0";
        }
        if ($this->post('createTime')) {
            $and .= self::timeComparison($this->post('createTime'), 'date', 'a.time');
        }
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'b.applyDate');
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'applyDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "field"=>"b.*,date(a.time) as costDate,a.type as costType,a.state,a.isPay,a.stid,a.deptName",
            "table" => "cost as a join cost_record as b on a.id = b.costId",
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        $_SESSION[self::page]['feeSql'] = $page['fullSql'];
        $_SESSION[self::page]['carId'] = $carId;
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array("");
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "detail" => array("title" => "费用报销详情", "click" => "newIframe('费用报销详情','" . root . "control/adIndex.html?cla=cost&fun=detail&id=" . $array['costId'] . "')"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'费用报销'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    case "isPay":
                        $row[] = $array['isPay']?'是':'否';
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => "cost as a join cost_record as b on a.id = b.costId",
            'single' => $where,
            'field'  => "ifnull(sum(b.money),0) as money",
        ]);
        $total    = [
            'money'        => self::lostZero($totalQuery['money']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='feeForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }
    /**
     * 费用汇总导出
     */
    #[NoReturn] public function exportFeeData()
    {
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = '你还没有导出的权限';
        } else {
            $data = [];
            $sql = $_SESSION[self::page]['feeSql'];
            $car = query(self::table,"id = '".$_SESSION[self::page]['carId']."'");
            $title = ['报销日期', '报销类型', '费用类型',  '发生日期','费用金额（'.static::$unit.'）','费用说明','报销人','报销人部门','审批状态', '拨付状态'];
            $result['array'] = sqlFind($sql);
            if (is_array($result['array'])) {
                foreach ($result['array'] as $array) {
                    $data[] = [
                        $array['costDate'],
                        $array['costType'],
                        $array['type'],
                        $array['applyDate'],
                        $array['money'],
                        $array['text'],
                        self::findStaff($array['stid']),
                        $array['deptName'],
                        $array['state'],
                        $array['isPay']?'是':'否'
                    ];
                }
            }
            $text = $this->control['name'] . "导出了车辆{$car['shortName']}{$car['carNo']}的费用汇总";
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $data, "车辆{$car['shortName']}{$car['carNo']}费用汇总.xlsx");
        }
        header("Location:" . getenv("HTTP_REFERER"));
        exit(0);
    }

    /*列表页-查询条件*/
    public function gasOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "加油站" => text(array("name" => "gasStation")),
                    "加油日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 加油记录
     */
    public function gas(): bool|string
    {
        $html = $this->gasOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','gasDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'gasDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 加油记录
     * @return bool|string
     */
    public function gasSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "gasStation" => $this->post('gasStation'),
        ];
        $equal = [
            'coid' => self::$coid
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_gas',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("gasForm", "gasId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "gasId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','gasDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆加油'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_gas',
            'single' => $where,
            'field'  => "ifnull(sum(volume),0) as volume,ifnull(sum(money),0) as money",
        ]);
        $total    = [
            'volume'        => $totalQuery['volume'],
            'money'        => self::lostZero($totalQuery['money']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='gasForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 加油记录
     * @return bool|string
     */
    public function gasDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_gas', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "加油日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
                "加油站：" => text(array("name" => "gasStation", "value" => $insure['gasStation'])),
            ),
            array(
                "油号：" => select(array("name" => "gasNo",'option'=>explode('，',para('gasNoOption')),'title'=>'油号', "value" => $insure['gasNo'])),
                "加油量：" => text(array("name" => "volume",'unit'=>'L', "value" => $insure['volume'])),
            ),
            array(
                "单价：" => text(array("name" => "price",'unit'=>static::$unit.'/L', "value" => $insure['price'])),
                "金额：" => text(array("name" => "money",'unit'=>static::$unit, "value" => $insure['money'])),
            ),
            array(
                must . "付款方式：" => radio(array("name" => "payType", 'value' =>['现金','油卡'], "checked" => $insure['payType'])),
                "油卡卡号：" => text(array("name" => "gasCard", "value" => $insure['gasCard'])),
            ),
            array(
                "备注：" => textarea(array("name" => "text",'class'=>'textarea', "value" => $insure['text'])),
            ),
            array(
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆加油', self::page, self::page . 'GasDetailForm'),
            ],
        ),
           'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "事故记录编辑",
            "height" => 450,
            "width" => 900,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarGasDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=gasEdit\')">保存</button>'
        ));
    }

    /**
     *加油记录
     * @return bool|string
     */
    public function gasEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'gasStation' => $this->post('gasStation'),
            'gasNo' => $this->post('gasNo'),
            'volume' => $this->post('volume'),
            'price' => $this->post('price'),
            'money' => $this->post('money'),
            'payType' => $this->post('payType'),
            'gasCard' => $this->post('gasCard'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '登记日期',
            'gasStation' => '加油站',
            'money' => '金额',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'gasStation' => 'required',
            'money' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_gas', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_gas', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_gas',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=gas&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }
    /*列表页-查询条件*/
    public function tollOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "起始站" => text(array("name" => "gasStation")),
                    "终点站" => text(array("name" => "gasNo")),
                    "费用日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }
    /**
     * 过路费记录
     */
    public function toll(): bool|string
    {
        $html = $this->tollOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','tollDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'tollDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 过路费记录
     * @return bool|string
     */
    public function tollSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "gasStation" => $this->post('gasStation'),
            "gasNo" => $this->post('gasNo'),
        ];
        $equal = [
            'coid' => self::$coid
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_toll',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("gasForm", "gasId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "gasId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','tollDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'过路费'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_toll',
            'single' => $where,
            'field'  => "ifnull(sum(volume),0) as volume,ifnull(sum(money),0) as money",
        ]);
        $total    = [
            'volume'        => $totalQuery['volume'],
            'money'        => self::lostZero($totalQuery['money']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='gasForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 过路费记录
     * @return bool|string
     */
    public function tollDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_toll', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "费用日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
                must ."起始站：" => text(array("name" => "gasStation", "value" => $insure['gasStation'])),
            ),
            array(
                must ."终点站：" => text(array("name" => "gasNo", "value" => $insure['gasNo'])),
                "公里数：" => text(array("name" => "volume",'unit'=>'KM', "value" => $insure['volume'])),
            ),
            array(
                "单价：" => text(array("name" => "price",'unit'=>static::$unit.'/KM', "value" => $insure['price'])),
                must . "金额：" => text(array("name" => "money",'unit'=>static::$unit, "value" => $insure['money'])),
            ),
            array(
                must . "付款方式：" => radio(array("name" => "payType", 'value' =>['现金','微信','支付宝','银行卡'], "checked" => $insure['payType'])),
                "付款卡号：" => text(array("name" => "gasCard", "value" => $insure['gasCard'])),
            ),
            array(
                "备注：" => textarea(array("name" => "text",'class'=>'textarea', "value" => $insure['text'])),
            ),
            array(
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '过路费', self::page, self::page . 'TollDetailForm'),
            ],
        ),
            'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "事故记录编辑",
            "height" => 450,
            "width" => 930,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarTollDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=tollEdit\')">保存</button>'
        ));
    }

    /**
     * 过路费记录
     * @return bool|string
     */
    public function tollEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'gasStation' => $this->post('gasStation'),
            'gasNo' => $this->post('gasNo'),
            'volume' => $this->post('volume'),
            'price' => $this->post('price'),
            'money' => $this->post('money'),
            'payType' => $this->post('payType'),
            'gasCard' => $this->post('gasCard'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '费用日期',
            'gasStation' => '起始站',
            'gasNo' => '终点站',
            'payType' => '付款方式',
            'money' => '金额',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'gasStation' => 'required',
            'gasNo' => 'required',
            'payType' => 'required',
            'money' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_toll', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_toll', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_toll',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=gas&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function illegalOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "类型" => text(array("name" => "type", 'option'=>$this->illegalType)),
                    "描述"   => text(array("name" => "description")),
                    "登记日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 事故违章
     */
    public function illegal(): bool|string
    {
        $html = $this->illegalOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','illegalDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'illegalDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 事故违章
     * @return bool|string
     */
    public function illegalSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "description" => $this->post('description'),
        ];
        $equal = [
            'type'=>$this->post('type'),
            'coid' => self::$coid,
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "asc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_illegal',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("illegalForm", "illegalId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "illegalId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','illegalDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆违章'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_illegal',
            'single' => $where,
            'field'  => "ifnull(sum(score),0) as score,ifnull(sum(reparation),0) as reparation,ifnull(sum(fine),0) as fine",
        ]);
        $total    = [
            'score'        => $totalQuery['score'],
            'reparation'        => self::lostZero($totalQuery['reparation']),
            'fine'        => self::lostZero($totalQuery['fine']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='illegalForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 事故违章
     * @return bool|string
     */
    public function illegalDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_illegal', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "登记日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
                must . "类型：" => radio(array("name" => "type", 'value' => $this->illegalType, "checked" => $insure['type'])),
            ),
            array(
                must ."描述：" =>textarea(array('name' => 'description', 'class' => 'textarea', 'value' => $insure['description']))
            ),
            array(
                "发生时间：" => text(array("name" => "happenTime",'laydate'=>['type'=>'datetime'], "value" => $insure['happenTime'])),
                "发生地点：" => text(array("name" => "address", "value" => $insure['address'])),
            ),
            array(
                "责任：" => select(array("name" => "responsibility",'option'=>explode('，',para('responsibility')),'title'=>'责任', "value" => $insure['responsibility'])),
                "扣分：" => text(array("name" => "score",'unit'=>'分', "value" => $insure['score'])),
            ),
            array(
                "罚款：" => text(array("name" => "fine",'unit'=>static::$unit, "value" => $insure['fine'])),
                "赔偿：" => text(array("name" => "reparation",'unit'=>static::$unit, "value" => $insure['reparation'])),
            ),
            array(
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆违章', self::page, self::page . 'IllegalDetailForm'),
            ],
        ),
           'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "事故记录编辑",
            "height" => 450,
            "width" => 1000,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarIllegalDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=illegalEdit\')">保存</button>'
        ));
    }

    /**
     *事故违章
     * @return bool|string
     */
    public function illegalEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'type' => $this->post('type'),
            'fine' => $this->post('fine'),
            'description' => $this->post('description'),
            'address' => $this->post('address'),
            'happenTime' => $this->post('happenTime'),
            'responsibility' => $this->post('responsibility'),
            'score' => $this->post('score'),
            'reparation' => $this->post('reparation'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '登记日期',
            'type' => '类型',
            'description' => '描述',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'type' => 'required',
            'description' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_illegal', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_illegal', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_illegal',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=illegal&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function repairOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "维修原因" => text(array("name" => "reason")),
                    "维修内容"   => text(array("name" => "text")),
                    "修配厂"   => text(array("name" => "factory")),
                ],
                [
                    "维修日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 维修记录
     */
    public function repair(): bool|string
    {
        $html = $this->repairOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','repairDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'repairDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 维修记录
     * @return bool|string
     */
    public function repairSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "text" => $this->post('text'),
            "factory" => $this->post('factory'),
            "reason" => $this->post('reason'),
        ];
        $equal = [
            'coid' => self::$coid,
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_repair',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("repairForm", "repairId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "repairId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','repairDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆维修'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_repair',
            'single' => $where,
            'field'  => "ifnull(sum(money),0) as money",
        ]);
        $total    = [
            'money'        => self::lostZero($totalQuery['money']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='repairForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 维修记录
     * @return bool|string
     */
    public function repairDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_repair', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "维修日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
                "维修原因：" =>text(array("name" => "reason",'class'=>'long', "value" => $insure['reason'])),
            ),
            array(
                must ."维修内容：" =>textarea(array('name' => 'text', 'class' => 'textarea', 'value' => $insure['text']))
            ),
            array(
                "修配厂：" => text(array("name" => "factory", "value" => $insure['factory'])),
                "维修费用：" => text(array("name" => "money",'unit'=>static::$unit, "value" => $insure['money'])),
            ),
            array(
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆维修', self::page, self::page . 'RepairDetailForm'),
            ],
        ),
            'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "维修记录编辑",
            "height" => 400,
            "width" => 900,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarRepairDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=repairEdit\')">保存</button>'
        ));
    }

    /**
     *维修记录
     * @return bool|string
     */
    public function repairEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'factory' => $this->post('factory'),
            'money' => $this->post('money'),
            'reason' => $this->post('reason'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '维修日期',
            'text' => '维修内容',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'text' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_repair', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_repair', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_repair',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=repair&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function maintainanceOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "到期预警" => select(array("name" => "isWarn", "option" => ['是', '否'])),
                    "保养内容"   => text(array("name" => "text")),
                    "修配厂"   => text(array("name" => "factory")),
                ],
                [
                    "保养日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])),
                    "下次保养日期" => text(array("name" => "insureDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 保养记录
     */
    public function maintainance(): bool|string
    {
        $html = $this->maintainanceOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','maintainanceDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'maintainanceDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 保养记录
     * @return bool|string
     */
    public function maintainanceSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "text" => $this->post('text'),
            "factory" => $this->post('factory'),
        ];
        $equal = [
            'coid' => self::$coid,
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        if ($this->post('insureDate')) {
            $and .= self::timeComparison($this->post('insureDate'), 'date', 'nextDate');
        }
        if ($this->post('isWarn') == '是') {
            $and .= " and nextDate<='" . $this->date . "'";
        } elseif ($this->post('isWarn') == '否') {
            $and .= " and nextDate>'" . $this->date . "'";
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_maintainance',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("maintainanceForm", "maintainanceId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "maintainanceId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','maintainanceDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆保养'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "isWarn":
                        $isWarn = strtotime($array['nextDate']) < time() ? "<span style='color:red'>是</span>" : '否';
                        $row[] = $isWarn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_maintainance',
            'single' => $where,
            'field'  => "ifnull(sum(money),0) as money",
        ]);
        $total    = [
            'money'        => self::lostZero($totalQuery['money']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='maintainanceForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 保养记录
     * @return bool|string
     */
    public function maintainanceDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_maintainance', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "保养日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
            ),
            array(
                must ."保养内容：" => textarea(array('name' => 'text', 'class' => 'textarea', 'value' => $insure['text']))
            ),
            array(
                "修配厂：" => text(array("name" => "factory", "value" => $insure['factory'])),
                "保养费用：" => text(array("name" => "money",'unit'=>static::$unit, "value" => $insure['money'])),
            ),
            array(
                "当前里程：" => text(array("name" => "mileage", 'unit'=>'km',"value" => $insure['mileage'])),
                "下次保养里程：" => text(array("name" => "nextMileage",'unit'=>'km', "value" => $insure['nextMileage'])),
            ),
            array(
                "下次保养日期：" => text(array("name" => "nextDate", 'laydate' => [], "value" => $insure['nextDate'])),
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆保养', self::page, self::page . 'MaintainanceDetailForm'),
            ],
        ),
            'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "保养记录编辑",
            "height" => 400,
            "width" => 900,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarMaintainanceDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=maintainanceEdit\')">保存</button>'
        ));
    }

    /**
     * 保养记录
     * @return bool|string
     */
    public function maintainanceEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'factory' => $this->post('factory'),
            'money' => $this->post('money'),
            'mileage' => $this->post('mileage'),
            'nextMileage' => $this->post('nextMileage'),
            'nextDate' => $this->post('nextDate'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '保养日期',
            'text' => '保养内容',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'text' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_maintainance', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_maintainance', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_maintainance',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=maintainance&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function inspectionOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "到期预警" => select(array("name" => "isWarn", "option" => ['是', '否'])),
                    "检验机构"   => text(array("name" => "agency")),
                    "合格标志号"   => text(array("name" => "markNo")),
                ],
                [
                    "检验日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])),
                    "检验有效期至" => text(array("name" => "insureDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 年审记录
     * @return bool|string
     */
    public function inspection(): bool|string
    {
        $html = $this->inspectionOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','inspectionDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'inspectionDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    /**
     * 年检记录
     * @return bool|string
     */
    public function inspectionSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "agency" => $this->post('agency'),
            "markNo" => $this->post('markNo'),
        ];
        $equal = [
            'coid' => self::$coid,
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'checkDate');
        }
        if ($this->post('insureDate')) {
            $and .= self::timeComparison($this->post('insureDate'), 'date', 'endDate');
        }
        if ($this->post('isWarn') == '是') {
            $and .= " and endDate<='" . $this->date . "'";
        } elseif ($this->post('isWarn') == '否') {
            $and .= " and endDate>'" . $this->date . "'";
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'endDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_inspection',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("inspectionForm", "inspectionId")
        );

        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "inspectionId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','inspectionDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆年检'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "isWarn":
                        $isWarn = strtotime($array['endDate']) < time() ? "<span style='color:red'>是</span>" : '否';
                        $row[] = $isWarn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
        ));
        $json['html'] = $page['hint'] . $button . "<form name='inspectionForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 年检记录
     * @return bool|string
     */
    public function inspectionDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_inspection', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "检验日期：" => text(array("name" => "checkDate", 'laydate' => [], "value" => $insure['checkDate'])),
                "检验机构：" => text(array("name" => "agency", "value" => $insure['agency'])),
            ),
            array(
                "合格标志号：" => text(array("name" => "markNo", "value" => $insure['markNo'])),
                must . "检验有效期至：" => text(array("name" => "endDate", 'laydate' => [], "value" => $insure['endDate'])),
            ),
            array(
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            array(
                '备注：' => textarea(array('name' => 'text', 'class' => 'textarea', 'value' => $insure['text']))
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆年检', self::page, self::page . 'InspectionDetailForm'),
            ],
        ),
            'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "年审记录编辑",
            "height" => 400,
            "width" => 900,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarInspectionDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=inspectionEdit\')">保存</button>'
        ));
    }

    /**
     * 年检记录
     * @return bool|string
     */
    public function inspectionEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'checkDate' => $this->post('checkDate'),
            'agency' => $this->post('agency'),
            'endDate' => $this->post('endDate'),
            'markNo' => $this->post('markNo'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'checkDate' => '检验日期',
            'endDate' => '检验有效日期至',
        ];
        $rules = [
            'carId' => 'required',
            'checkDate' => 'required',
            'endDate' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_inspection', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_inspection', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_inspection',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=inspection&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function insureOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "到期预警" => select(array("name" => "isWarn", "option" => ['是', '否'])),
                    "保险人"   => text(array("name" => "insurer")),
                    "备注"   => text(array("name" => "text")),
                ],
                [
                    "登记日期" => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])),
                    "保险到期日期" => text(array("name" => "insureDate", 'laydate' => ['type' => 'date', 'range' => '~'])).
                        hidden(array('name' => 'id', 'value' => $this->get('id'))),
                ]
            ]
        ]);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 保险记录
     */
    public function insure(): bool|string
    {
        $html = $this->insureOptions(false);
        $carId = $this->get('id');
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('" . self::page . "','insureDetail',{id:'" . suiji() . "',carId:'" . $carId . "'})\" class='spanButton'>新增</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {act:'insureDel',id:'" . $this->post('id') . "'})\">删除</span>\n";
        }
        $json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
        return json_encode($json, 320);
    }

    public function insureSearch(): bool|string
    {
        $carId = $this->post('id');
        $where = " and carId = '$carId'";
        $and = '';
        $like = [
            "insurer" => $this->post('insurer'),
            "text" => $this->post('text'),
        ];
        $equal = [
            'coid' => self::$coid,
        ];
        if ($this->post('recordDate')) {
            $and .= self::timeComparison($this->post('recordDate'), 'date', 'recordDate');
        }
        if ($this->post('insureDate')) {
            $and .= self::timeComparison($this->post('insureDate'), 'date', 'endDate');
        }
        if ($this->post('isWarn') == '是') {
            $and .= " and endDate<='" . $this->date . "'";
        } elseif ($this->post('isWarn') == '否') {
            $and .= " and endDate>'" . $this->date . "'";
        }
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        //排序
        $orderBy = $this->listSort(array(
            "search" => $this->post('list_sort_key') ?: 'recordDate',
            "sort"   => $this->post('list_sort') ?: "desc",
            "array"  => array(),
        ));
        $page = $this->page([
            "table" => 'logistics_car_insure',
            "where" => $where,
            "order" => $orderBy['orderBy']
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("insureForm", "insureId")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "insureId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','insureDetail',{id:'" . $array['id'] . "',carId:'" . $array['carId'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "fileBtn":
                        $num = static::total(array('table' => 'file', 'where' => "targetId = '" . $array['id'] . "'"));
                        $fileBtn = $num > 0 ? "<span style='cursor: pointer;color: #629afd' onclick=\"layer('logisticsCar','fileDetail',{id:'" . $array['id'] . "',type:'车辆保险'})\">" . $num . "</span>" : '';
                        $row[] = $fileBtn;
                        break;
                    case "startDate":
                        $row[] = $array['startDate'] . '至' . $array['endDate'];
                        break;
                    case "isWarn":
                        $isWarn = strtotime($array['endDate']) < time() ? "<span style='color:red'>是</span>" : '否';
                        $row[] = $isWarn;
                        break;
                    case "stid":
                        $row[] = self::findStaff($array['stid']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        $totalQuery = find([
            'table'  => 'logistics_car_insure',
            'single' => $where,
            'field'  => "ifnull(sum(insureFee),0) as insureFee,ifnull(sum(insureMoney),0) as insureMoney",
        ]);
        $total    = [
            'insureFee'        => self::lostZero($totalQuery['insureFee']),
            'insureMoney'        => self::lostZero($totalQuery['insureMoney']),
        ];
        //生成页面
        $li = $this->li(array(
            "body"        => $body,
            "install"     => $installSearch,
            "button"      => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page"        => $page['para'],
            "total"       => $total,
        ));
        $json['html'] = "<form name='insureForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 显示文件
     */
    public function fileDetail(): bool|string
    {
        $id = $this->post('id');
        $type = $this->post('type');
        //生成表单
        $html = $this->layerEdit(
            array(
                "table" => array(
                [
                    "附件：" => fileUploadClass::showFile($id, $type),
                ],
            ),
        ));
        //返回
        return $this->layer(array("title" => "文件", "height" => 400, "width" => 900, "html" => $html, "button" => false));

    }

    /**
     * 编辑
     * @return bool|string
     */
    public function insureDetail(): bool|string
    {
        $id = $this->post('id');
        $insure = query('logistics_car_insure', " id = '{$this->post('id')}'");
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . "登记日期：" => text(array("name" => "recordDate", 'laydate' => [], "value" => $insure['recordDate'])),
                must . "保险人：" => text(array("name" => "insurer", "value" => $insure['insurer'])),
            ),
            array(
                must . "保险期间：" => text(array("name" => "chooseDate", 'class' => 'width300', 'laydate' => ['range' => '~'], "value" => strtotime($insure['startDate']) > 0 ? $insure['startDate'] . ' ~ ' . $insure['endDate'] : '')),
                "保费：" => text(array("name" => "insureFee", "value" => $insure['insureFee'])),
            ),
            array(
                "保额：" => text(array("name" => "insureMoney", "value" => $insure['insureMoney'])),
                "经办人：" => selectMultiple(array('name' => 'stid', 'table' => 'staff', 'sqlId' => 'stid', 'sqlField' => 'name', 'where' => "state !='离职'", 'value' => $insure['stid'], 'title' => '经办人')),
            ),
            array(
                '备注：' => textarea(array('name' => 'text', 'class' => 'textarea', 'value' => $insure['text']))
            ),
            [
                "附件：" => fileUploadClass::addFileComponent($id, '车辆保险', self::page, self::page . 'InsureDetailForm'),
            ],
        ),
            'hidden' => hidden(array('name' => 'carId', 'value' => $this->post('carId'))),

        ));
        //返回
        return $this->layer(array(
            "title" => "保险记录编辑",
            "height" => 400,
            "width" => 900,
            "html" => $html,
            'button' => '<button class="button" onclick="subForm(\'logisticsCarInsureDetailForm\',root+\'control/adIndex.html?cla=logisticsCar&fun=insureEdit\')">保存</button>'
        ));
    }

    /*保险记录-异步处理*/
    public function insureEdit(): bool|string
    {
        $fileId = $this->post('fileId') ?? [];
        $id = $this->post('id') ?: self::getId();
        $timeArr = explode(' ~ ', $this->post('chooseDate'));
        $field = [
            'carId' => $this->post('carId'),
            'stid' => $this->post('stid'),
            'recordDate' => $this->post('recordDate'),
            'insurer' => $this->post('insurer'),
            'startDate' => $timeArr[0] ?? '',
            'endDate' => $timeArr[1] ?? '',
            'insureFee' => $this->post('insureFee'),
            'insureMoney' => $this->post('insureMoney'),
            'text' => $this->post('text'),
        ];
        $annotation = [
            'carId' => '车辆ID',
            'recordDate' => '登记日期',
            'insurer' => '保险人',
            'startDate' => '保险期间',
            'endDate' => '保险期间',
        ];
        $rules = [
            'carId' => 'required',
            'recordDate' => 'required',
            'insurer' => 'required',
            'startDate' => 'required',
            'endDate' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $where = " id = '$id' ";
        $info = query('logistics_car_insure', $where);
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        } else {
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                ]);
                $json['warn'] = static::insert(["table" => 'logistics_car_insure', "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'logistics_car_insure',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                if (is_array($fileId) && !static::isNull($fileId)) {
                    update(['table' => 'file', 'field' => ['targetId' => $id], 'where' => " targetId = '' and id in ('" . implode("','", $fileId) . "')"]);
                }
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&menu=insure&id=" . $field['carId'];
            }
        }

        resp:
        return json_encode($json, 320);
    }


    /**
     * 导入模板字段初始化
     * @return array[]
     */
    public function importFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'车牌号',
                    'aliasName'=>'车牌号',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'车辆品牌',
                    'aliasName'=>'车辆品牌',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'规格型号',
                    'aliasName'=>'规格型号',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'车辆类型',
                    'aliasName'=>'车辆类型',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'核定载人数',
                    'aliasName'=>'核定载人数',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'核定载重',
                    'aliasName'=>'核定载重(kg)',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'燃油类型',
                    'aliasName'=>'燃油类型',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'排量',
                    'aliasName'=>'排量',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'车架号',
                    'aliasName'=>'车架号',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'资产原值',
                    'aliasName'=>'资产原值',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'开始使用日期',
                    'aliasName'=>'开始使用日期',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'管理员',
                    'aliasName'=>'管理员',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'管理员编号',
                    'aliasName'=>'管理员编号',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'使用期限',
                    'aliasName'=>'使用期限(月)',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'折价期限',
                    'aliasName'=>'折价期限(月)',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'状态',
                    'aliasName'=>'状态(正常/维修/报废)',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',
                    'isMust'=>false,
                ],
            ]
        };
    }

    /**
     * 导出模板字段初始化
     * @return array[]
     */
    public function exportFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'车辆编号',
                    'aliasName'=>'车辆编号',
                ],
                [
                    'columnName'=>'车牌号',
                    'aliasName'=>'车牌号',
                ],
                [
                    'columnName'=>'车辆品牌',
                    'aliasName'=>'车辆品牌',
                ],
                [
                    'columnName'=>'规格型号',
                    'aliasName'=>'规格型号',
                ],
                [
                    'columnName'=>'车辆类型',
                    'aliasName'=>'车辆类型',
                ],
                [
                    'columnName'=>'核定载人数',
                    'aliasName'=>'核定载人数',
                ],
                [
                    'columnName'=>'核定载重',
                    'aliasName'=>'核定载重(kg)',
                ],
                [
                    'columnName'=>'燃油类型',
                    'aliasName'=>'燃油类型',
                ],
                [
                    'columnName'=>'排量',
                    'aliasName'=>'排量',
                ],
                [
                    'columnName'=>'车架号',
                    'aliasName'=>'车架号',
                ],
                [
                    'columnName'=>'资产原值',
                    'aliasName'=>'资产原值(元)',
                ],
                [
                    'columnName'=>'开始使用日期',
                    'aliasName'=>'开始使用日期',
                ],
                [
                    'columnName'=>'管理员',
                    'aliasName'=>'管理员',
                ],
                [
                    'columnName'=>'使用期限',
                    'aliasName'=>'使用期限(月)',
                ],
                [
                    'columnName'=>'折价期限',
                    'aliasName'=>'折价期限(月)',
                ],
                [
                    'columnName'=>'驾驶人',
                    'aliasName'=>'驾驶人',
                ],
                [
                    'columnName'=>'状态',
                    'aliasName'=>'状态',
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',
                ],
                [
                    'columnName'=>'创建人',
                    'aliasName'=>'创建人',
                ],
                [
                    'columnName'=>'创建时间',
                    'aliasName'=>'创建时间',
                ],
            ]
        };
    }
}
